﻿<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/qautil.tld" prefix="qautil"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<!-- answers -->
<c:set var="resultSize" value="${fn:length(questiono.mrIaskAnswers)}" scope="request"/>
<c:if test="${resultSize > 0}">
<br>
<div style="margin-bottom:0;background:url(qa/images/mr-qa-answer-title.gif) no-repeat left"><span style="float:left;"><img src="qa/images/mr-qa-answer-title.gif" border="0" alt=""/></span>
<span style="float:right;cursor:hand;" onclick="expandAnswers();" id="answersDivOpenIndicator" title="关闭"><img id="imgSwitchor" src="qa/images/ico_collapse.gif"/><img src="qa/images/blank.gif" width="5" height="0"/></span></div>
<script type="text/javascript">
    function expandAnswers()
    {
        var answersDiv = document.getElementById("answersDiv");
        var answersDivOpenIndicator = document.getElementById("answersDivOpenIndicator");
        var imgSwitchor = document.getElementById("imgSwitchor");
        if(answersDiv.style.display == "none")
        {
            answersDiv.style.display = "block";
            imgSwitchor.src = "qa/images/ico_collapse.gif";
            answersDivOpenIndicator.title = "关闭";
        }
        else
        {
            answersDiv.style.display = "none";
            imgSwitchor.src = "qa/images/ico_expand.gif";
            answersDivOpenIndicator.title = "展开";
        }
    }
</script>
        <c:choose>
            <c:when test="${(empty param.page) and (empty page)}">
                <c:set var="page" value="1" scope="request"/>
            </c:when>
            <c:when test="${not empty param.page}">
                <c:set var="page" value="${param.page}" scope="request"/>
            </c:when>
        </c:choose>
        <c:choose>
            <c:when test="${empty param.pageSize}">
                <%
                    request.setAttribute("pageSize",""+com.mr.qa.GlobalConfigs.NUMBER_ANSWER_FOR_VIEW_QUESTION);
                %>
            </c:when>
            <c:when test="${not empty param.pageSize}">
                <c:set var="pageSize" value="${param.pageSize}" scope="request"/>
            </c:when>
        </c:choose>
        <c:set var="begin" value="${(page-1)*pageSize}"/>
        <c:set var="end" value="${page*pageSize-1}"/>
        <div style="background-color:#FAFCFC;width:720;padding:4px 4px 4px 4px;border:1px solid #ccc;" id="answersDiv">
        <c:forEach var="answer" items="${questiono.mrIaskAnswers}" begin="${begin}" end="${end}">
        <table cellpadding="0" cellspacing="0" border="0" style="width:710;word-wrap:break-word;table-layout:fixed;">
         <tr>
            <td width="145" valign="top">
                <c:if test="${not empty answer.mrIaskUser and not answer.isAnonymous}">
                    <div>
                    	<table border="0">
            						<tr>
            							<td valign="top">
            								<c:choose>
															<c:when test="${answer.mrIaskUser.headerImage == null}" >
																<img src="qa/images/header_default50.jpg" width="50" height="50">
															</c:when>
															<c:otherwise>
																<html:img page="header${answer.mrIaskUser.headerImage}" width="50" height="50"/>
															</c:otherwise>
														</c:choose>
            							</td>
            							<td valign="top">
            								<c:if test="${answer.mrIaskUser.isSuper}">职务：<font color=blue>版主</font><br></c:if>
            								<c:if test="${answer.mrIaskUser.type == '1'}">职务：<font color=green>管理员</font><br></c:if>
            								发帖：<c:out value="${answer.mrIaskUser.questionsCount}"/><br>
            								回复：<c:out value="${answer.mrIaskUser.answersCount}"/>
            							</td>
            						</tr>
            					</table>
                    <span style="width:80;">
                    <c:set var="user_id" value="${answer.mrIaskUser.id}"/>
                    <html:link page="/user.mrqa?action=viewuserbyother" styleId="author" paramId="id" paramName="user_id"><b><c:out value="${answer.mrIaskUser.loginName}"/></b></html:link>
                    </span>
                    <span>
                    <c:if test="${not empty user_session}">
                    <c:url value="/msg.mrqa" var="pmLink">
                        <c:param name="action" value="preadd"/>
                        <c:param name="toUserLoginName" value="${answer.mrIaskUser.loginName}"/>
                    </c:url>
                    <a href="<c:out value="${pmLink}"/>" title="给我短信"><img src="qa/images/icon/pm.gif" border="0" alt="给我短信"/></a>
                    </c:if>
                    </span>
                    </div>
                    <c:out value="${answer.mrIaskUser.userScore.title}"/>
                </c:if>
                <c:if test="${not empty answer.mrIaskUser and answer.isAnonymous}">
                    <c:if test="${user_session.type == '1'}">
                        <div>
                        <span style="width:80;">
                        <c:set var="user_id" value="${answer.mrIaskUser.id}"/>
                        <html:link page="/user.mrqa?action=viewuserbyother" styleId="author" paramId="id" paramName="user_id"><b><c:out value="${answer.mrIaskUser.loginName}"/></b></html:link>
                        </span>
                        <span>
                        <c:if test="${not empty user_session}">
                        <c:url value="/msg.mrqa" var="pmLink">
                            <c:param name="action" value="preadd"/>
                            <c:param name="toUserLoginName" value="${answer.mrIaskUser.loginName}"/>
                        </c:url>
                        <a href="<c:out value="${pmLink}"/>" title="给我短信"><img src="qa/images/icon/pm.gif" border="0" alt="给我短信"/></a>
                        </c:if>
                        </span><br>
                        匿名&nbsp;IP:<c:out value="${answer.anonymousUser}"/><br>
                        </div>
                    </c:if>
                    <c:if test="${empty user_session or user_session.type == '0'}">
                        IP:<c:out value="${answer.anonymousUser}"/><br>
                    </c:if>
                </c:if>
                <c:if test="${empty answer.mrIaskUser}">
                    IP:<c:out value="${answer.anonymousUser}"/><br>
                </c:if>
                <br><br>
                <fmt:formatDate value="${answer.postDate}" type="both" pattern="yyyy-MM-dd HH:mm"/>
                <c:if test="${user_session.type == '1' and not empty answer.anonymousUser and not answer.isAnonymous}">
                	<br>IP:<c:out value="${answer.anonymousUser}"/>
                </c:if>
            </td>
            <td valign="top">
                <pre style="white-space: pre-wrap;"><c:out escapeXml="false" value="${fn:replace(answer.content,'<image=','<img name=contentimg border=0 src=')}"/></pre>
                <p>                    
                    <c:if test="${fn:length(answer.reference) > 0}">
                        参考：<c:out value="${answer.reference}"/>&nbsp;&nbsp;&nbsp;
                    </c:if>
                    <c:if test="${fn:length(answer.file) > 0}">
                        附件：<c:out value="${answer.file}"/>
                    </c:if>                        
                </p>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="right" style="border-bottom:1px dotted #ccc;">
            <div>
            <c:if test="${answer.mrIaskUser != null}">
                <span style="float:left;text-indent:144px;padding:3 0 3 0;">
                    <c:if test="${not answer.isAnonymous}">
                个人签名:&nbsp;&nbsp;<font color="blue"><c:out value="${answer.mrIaskUser.signature}"/></font>
                    </c:if>&nbsp;
                </span>
                <span style="float:right;padding:3 0 3 0;">
                <c:if test="${user_session.userId == answer.mrIaskUser.id}">
                        <c:url value="/answer.mrqa" var="modiAnswerLink">
                            <c:param name="action" value="premodify"/>
                            <c:param name="id" value="${answer.id}"/>
                            <c:param name="page" value="${page}"/>
                            <c:param name="pageSize" value="${pageSize}"/>
                        </c:url>
                        <%request.setAttribute("curDate",new java.util.Date());%>
                        <%request.setAttribute("ANSWER_EXPIRY_NUMBER", com.mr.qa.GlobalConfigs.ANSWER_EXPIRY_NUMBER);%>
                        <c:set var="canAModify" value="false"/>
                        <c:set var="differADay" value="${(curDate.time-answer.postDate.time)/1000/60/60/24}"/>
                        <c:if test="${differADay <= ANSWER_EXPIRY_NUMBER}">
                            <c:set var="canAModify" value="true"/>
                        </c:if>
                        <c:if test="${canAModify}">
                            <a href="<c:out value="${modiAnswerLink}"/>" target="modifyAnswerFrame" onclick='modifyAnswer(this);'>修改</a>
                        </c:if>
                        <%
                            request.setAttribute("ANSWER_CAN_DELETE_DURATION_AFTER_ADD", com.mr.qa.GlobalConfigs.ANSWER_CAN_DELETE_DURATION_AFTER_ADD);
                        %>
                        <c:set var="differAHour" value="${(curDate.time-answer.postDate.time)/1000/60/60}"/>
                        <c:if test="${differAHour <= ANSWER_CAN_DELETE_DURATION_AFTER_ADD}">
                            &nbsp;|&nbsp;
                            <html:link page="/answer.mrqa?action=predelete" paramId="id" paramName="answer" paramProperty="id">删除</html:link>
                        </c:if>
                </c:if>
                <c:if test="${user_session.userId != answer.mrIaskUser.id and adminRight == true}">
                    <html:link page="/answer.mrqa?action=predelete" paramId="id" paramName="answer" paramProperty="id">删除</html:link>
                </c:if>
                </span>
            </c:if>
            <c:if test="${answer.mrIaskUser == null and adminRight == true}">
                <span style="float:right;padding:3 0 3 0;"><html:link page="/answer.mrqa?action=predelete" paramId="id" paramName="answer" paramProperty="id">删除</html:link>&nbsp;&nbsp;&nbsp;</span>
            </c:if>&nbsp;
            </div>
            </td>
        </tr>
        <tr>
        <td height="7"></td>
        </tr>
        </table>
       </c:forEach>
       <!--2--> 
</div>
</c:if>
<!-- pagination -->
<div><qautil:page action="/question.mrqa"/></div>
<c:if test="${canAModify}">
<div id="modifyAnswerDiv" style="display:none;">
    <br>
    <table border="0" cellpadding="0" cellspacing="0" align="center" width="720">
        <tr style="background:url(qa/images/dothline.gif) bottom;">
            <td width="720">
            &nbsp;&nbsp;&nbsp;&nbsp;<b>修改回复</b>
            </td>
        </tr>
    </table>
    <div style="width:720;padding:12px 0px 0px 4px;border-left:1px dotted #ccc;border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;">
    <iframe src="about:blank" frameborder="0" scrolling="auto" name="modifyAnswerFrame" id="modifyAnswerFrame" width="100%" height="250"></iframe>
    </div>
    <input type="hidden" name="mafocus"/>
    <script type="text/javascript">
        function modifyAnswer(link)
        {
            var addAnswerDiv = document.getElementById("addAnswerDiv");        
            if(addAnswerDiv.style.display == "block" || addAnswerDiv.style.display == "")
                addAnswerDiv.style.display = "none";
            var modifyAnswerDiv = document.getElementById("modifyAnswerDiv");
            if(modifyAnswerDiv.style.display == "none")
                modifyAnswerDiv.style.display = "block";
            var trainingDiv = document.getElementById("trainingDiv");
            if(trainingDiv != null)
                if(trainingDiv.style.display == "block" || trainingDiv.style.display == "")
                    trainingDiv.style.display = "none";
            self.scrollTo(document.body.scrollWidth,document.body.scrollHeight);
        }
    </script>
</div>
</c:if>

<%request.setAttribute("curDate",new java.util.Date());%>
<c:set var="differDay" value="${(curDate.time-questiono.postDate.time)/1000/60/60/24}"/>
<%request.setAttribute("QUESTION_LOCK_NUMBER", com.mr.qa.GlobalConfigs.QUESTION_LOCK_NUMBER);%>

<!-- add answer form -->
<c:if test="${questiono.state != '4' and questiono.isLocked == false and questiono.mrIaskCategory.isLock == false and differDay < QUESTION_LOCK_NUMBER}">
<div id="addAnswerDiv">
<br>
<!-- end x -->
<html:form action="/answer" enctype="multipart/form-data" focus="content" onsubmit="return validate(this);">
<html:hidden property="action" value="add"/>
<html:hidden property="page"/>
<html:hidden property="pageSize"/>
<input type="hidden" name="questionId" value="<c:out value="${questiono.id}"/>"/>
<table border="0" cellpadding="0" cellspacing="0" align="center" width="720">
    <tr style="background:url(qa/images/dothline.gif) bottom;">
        <td width="720">
        &nbsp;&nbsp;&nbsp;&nbsp;<b>我来回复</b>
        </td>
    </tr>
</table>
<div style="width:720;padding:12px 4px 4px 4px;border-left:1px dotted #ccc;border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;">
<table align="center" width="100%" cellpadding="0" cellspacing="0">
   <tr>
        <td align="left" width="150" valign="top">
        <a name="answer"></a><jsp:include page="help-insertpicture.jsp?id=2"/>
        </td>
        <td>
            <html:textarea property="content" cols="77" rows="10"/>
        </td>
    </tr>
   <tr>
        <td align="right">参考:</td>
        <td>
            <html:text property="reference" value="http://" size="105"/>
        </td>
    </tr>
    <tr>
        <td align="right">图片:</td>
        <td>
            <iframe name="ad" id="ad" frameborder="0" width="100%" height="25" scrolling="no" src="/question.mrqa?action=uploadImage&imageIn=answer&imageArea=answer.content"></iframe>
        </td>
    </tr>
   <tr>
        <td align="right">&nbsp;</td>
        <td>
            <input type="submit" value="提交回复" name="submitButt"/>&nbsp;&nbsp;&nbsp;&nbsp;<html:checkbox property="anonymous"/>匿名回复&nbsp;&nbsp;&nbsp;&nbsp;(登录后才能匿名回复,匿名回复不增加积分)
        </td>
    </tr>
    </html:form>
</table>
</div>
</div>
</c:if>
<input type="hidden" name="addAnswerFocus" id="addAnswerFocus"/>
<script type="text/javascript">
    var prohibitedWords = "<%=com.mr.qa.GlobalConfigs.PROHIBITED_WORDS%>";
    function validate(pForm)
    {
        var content = pForm.content.value;
        if(content == "" || content.length < 1)
        {
            alert("[内容]必须填写，长度必须大于0");
            pForm.content.focus();
            return false;
        }
        var wordsCheckResult = wordsCheck(content);        
        if(!wordsCheckResult)
        {
            alert("[内容]含有非法字符");
            pForm.content.focus();return false;
        }
        pForm.submitButt.disabled = true;
        
        var uploadImage = frames["ad"].window.document.getElementById("uploadButton");
        if(uploadImage){
    			uploadImage.disabled = true;
    		}
        return true;
    }
    function onVote(pSubmit)
    {
        pSubmit.form.action = "vote";
    }
    function onSetPollItems(pSubmit)
    {
        pSubmit.form.action = "setpollitems";
    }
    /*
    * keywords validation
    */
    function wordsCheck(title)
    {
        var prohibitedWordArr = prohibitedWords.split(",");
        var prohibitedWord;
        for(var i=0;i<prohibitedWordArr.length;i++)
        {
            prohibitedWord = prohibitedWordArr[i];
            if(prohibitedWord.length > 0 && title.indexOf(prohibitedWord) >= 0)
            {
                return false;
            }
        }
        return true;
    }
</script>